<?php
$dbParams = parse_ini_file('db.properties');

$dbhost = $dbParams['host'];
$dbuser = $dbParams['user'];
$dbpass = $dbParams['pwd'];

$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql ' . mysql_error());

$dbname = $dbParams['name'];
mysql_select_db($dbname);

// очистить всё
echo '<div align="center" id="clearTags" class="notselected"><span id="m_clearTags"></span></div>';

// типы
echo '<div align="center"><table cellpadding="0" cellspacing="0"><tr>';
/*$statement = 'select tag.name, count(video_tag.video_id) from tag, video_tag where type=2 and tag.id=video_tag.tag_id group by video_tag.tag_id';
 $res = mysql_query($statement);
 echo '<td><div class="tl" align="center"><span id="m_type"></span></div></td><td>';
 echo '<table align="center" cellspacing="0" cellpadding="0"><tr>';
 while($row = mysql_fetch_array($res, MYSQL_NUM)) {
 if((int) $row[1] != 0) {
 $type = str_replace(" ", "", $row[0]);
 if($type == 'singlerope')
 $type = 'SR';
 else if($type == 'chinesewhill')
 $type = 'CW';
 else if($type == 'doubledutch')
 $type = 'DD';
 echo '<td><div class="type" type="' . $row[0] . '" title="' . $row[0] . '">' . $type . '</div></td>';
 }
 }
 echo '</tr></table>';
 echo '</td><td>';
 */
// уровни
$statement = 'select tag.name, count(video_tag.video_id) from tag, video_tag where type=1 and tag.id=video_tag.tag_id group by video_tag.tag_id order by tag.name';
$res = mysql_query($statement);
echo '<td><div class="tl" align="center"><span id="m_level"></span></div></td>';
echo '<td><table align="center" cellspacing="0" cellpadding="0"><tr>';
while($row = mysql_fetch_array($res, MYSQL_NUM)) {
	if((int) $row[1] != 0) {
		$level = str_replace(" ", "", $row[0]);
		echo '<td><div class="level" level="' . $row[0] . '" title="' . $row[0] . '">' . substr($level, -1, 1) . '</div></td>';
	}
}
echo '</tr></table>';
echo '</td></tr></table></div>';


$statement = 'select tag.name, count(video_tag.video_id), tag.msg_id from tag, video_tag where type=0 and tag.id=video_tag.tag_id group by video_tag.tag_id';
$res = mysql_query($statement);
$selected_tags = '';

echo "<div id='hrefs'>";
while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
	if((int) $row[1] != 0) {
		$fontSize = (int) $row[1];
		$style = "tag1";
		if($fontSize < 3)
		$style = "tag1";
		else if($fontSize < 6)
		$style = "tag2";
		else if($fontSize < 11)
		$style = "tag3";
		else if($fontSize < 21)
		$style = "tag4";
		else
		$style = "tag5";
		echo '<span class="tag ' . $style . '" tag="' . $row[0] . '"><span class="tagMsg" id="t.' . $row[2] . '"></span></span> &nbsp;';
	}
}

echo '</div>';

mysql_free_result($res);
mysql_close($conn);

?>